﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using LogLib;
using System.IO;
using ComLib.ComFun;

namespace DetectProcessing
{
    internal class Common
    {
        public static void CheckError(ArrayList alErrDesc, ref RecogOut detecRes)
        {
            string strLog;
            if (alErrDesc.Contains("曝光不足"))
            {
                detecRes.Correction.BrightnessOffset = 1;
                strLog = string.Format("增加曝光");
                Log.WriteAsync(strLog);
            }
            else if (alErrDesc.Contains("曝光过度"))
            {
                detecRes.Correction.BrightnessOffset = -1;
                strLog = string.Format("减少曝光");
                Log.WriteAsync(strLog);
            }
            else if (alErrDesc.Contains("头长过大"))
            {
                detecRes.Correction.HeadHeightOffSet = -1;
                strLog = string.Format("头长过大");
                Log.WriteAsync(strLog);
            }
            if (alErrDesc.Count > 0)
            {
                StringBuilder strErr = new StringBuilder();
                for (int i = 0; i < alErrDesc.Count; i++)
                {
                    strErr.Append(alErrDesc[i].ToString());
                    if (i < alErrDesc.Count - 1)
                    {
                        strErr.Append(";");
                    }
                }
                detecRes.Correction.Tips = strErr.ToString();
                detecRes.PassElems.Front = false;           
            }
        }

        public static bool OnImageFormatInverting(string srcPath, string savePath)
        {
            string strLog = "";
            ImageResizing handler = new ImageResizing(srcPath, savePath);
            if (!handler.OnHandling())
            {
                strLog = string.Format("格式转换失败");
                Log.WriteAsync(strLog);
                return false;
            }
            if (!File.Exists(savePath))
            {
                strLog = "格式转换失败,找不到文件";
                Log.WriteAsync(strLog);
                return false;
            }
            strLog = string.Format("格式转换完成");
            Log.WriteAsync(strLog);
            return true; ;
        }
    }
}
